/*******************************************************************************************************************
 * The MIT License (MIT)
 *
 * Copyright (c) 2014 Nicolas DAURES
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *******************************************************************************************************************/
 

/****************************************************************
 * Sound
 ****************************************************************/

// Sound
function Sound()
{
	//=======================
	// Fields
	//=======================
	
    this.m_Audio =  null;
};


//=======================
// Accessors
//=======================

Sound.prototype.getAudio = function()
{
    return this.m_Audio;
}

Sound.prototype.setAudio = function(a_Audio)
{
    this.m_Audio = a_Audio;
}

Sound.prototype.isLoop = function()
{
    return this.m_Audio.loop;
}

Sound.prototype.setLoop = function(a_bIsLoop)
{
    this.m_Audio.loop = a_bIsLoop;
}

Sound.prototype.getVolume = function()
{
    return this.m_Audio.volume;
}

Sound.prototype.setVolume = function(a_fVolume)
{
    this.m_Audio.volume = a_fVolume;
}

Sound.prototype.getPitch = function()
{
    return this.m_Audio.playbackRate;
}

Sound.prototype.setPitch = function(a_fPitch)
{
    this.m_Audio.playbackRate = a_fPitch;
}


//=======================
// Operations
//=======================

Sound.prototype.play = function()
{
    this.m_Audio.play();
}

Sound.prototype.pause = function()
{
    this.m_Audio.pause();
}


/****************************************************************
 * Audio Engine
 ****************************************************************/

// Audio engine
function AudioEngine()
{
	//=======================
	// Fields
	//=======================

	this.m_aSound =	 new Array();
}


//=======================
// Operations
//=======================

AudioEngine.prototype.update = function()
{

}

AudioEngine.prototype.addSound = function(a_Sound)
{
    this.m_aSound.push(a_Sound);
}

AudioEngine.prototype.playSound = function(a_iSound)
{
    this.m_aSound[a_iSound].play();
}


AudioEngine.m_Instance = null;
AudioEngine.getInstance = function()
{  
    if (this.m_Instance == null)
    {  
		this.m_Instance = new AudioEngine();  
    }  

    return this.m_Instance;  
}
